package com.lanou.musicbox.adapter.seekmusic;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.lanou.musicbox.R;
import com.lanou.musicbox.bean.SingerContentEntity;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by 赵宝龙 on 15/10/23.
 * 进入搜索_进入歌手Adapter
 */
public class EnterThe_Singer_Adapter extends BaseAdapter {
    private Context mContext;
    private List<SingerContentEntity.DataEntity> data;

    public EnterThe_Singer_Adapter(Context mContext) {
        this.mContext = mContext;
    }

    public void setDatas(List<SingerContentEntity.DataEntity> data) {
        this.data = data;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return data != null && data.size() > 0 ? data.size() : 0;
    }

    @Override
    public Object getItem(int position) {
        return data != null && data.size() > 0 ? data.get(position) : null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.enterthe_singer_list_item, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        SingerContentEntity.DataEntity entity = (SingerContentEntity.DataEntity) getItem(position);
        if (entity != null) {
            holder.songSinger.setText(entity.getSingerName());
            holder.songFivortNum.setText(entity.getFavorites() + "");
            holder.songTitle.setText(entity.getName());
            holder.songListTime.setText(position + 1 + "");
        }
        return convertView;
    }
    /**
     * This class contains all butterknife-injected Views & Layouts from layout file 'singer_list_content.xml'
     * for easy to all layout elements.
     *
     * @author ButterKnifeZelezny, plugin for Android Studio by Avast Developers (http://github.com/avast)
     */
    static class ViewHolder {
        @Bind(R.id.song_list_time)
        TextView songListTime;
        @Bind(R.id.song_title)
        TextView songTitle;
        @Bind(R.id.song_singer)
        TextView songSinger;
        @Bind(R.id.heart)
        ImageView heart;
        @Bind(R.id.song_fivort_num)
        TextView songFivortNum;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
